import { createRouter, createWebHistory } from 'vue-router'
import Layout from '../layout/Layout'
import desktop from '../components/desktop/index'

const routes = [
  {
    path: '/',
    name: 'Layout',
    component: Layout,
    redirect: "/home",
    children:[
      {
        path: 'user',
        name: 'User',
        component:  () => import("@/views/UserView"),
      },
      {
        path: 'home',
        name: 'Home',
        component:  () => import("@/views/HomeView"),
      },
      {
        path: 'problem',
        name: 'Problem',
        component:  () => import("@/views/ProblemView"),
      },
      {
        path: 'sourceAndType',
        name: 'SourceAndType',
        component:  () => import("@/views/SourceAndTypeView"),
      },
      {
        path: 'raceAndWork',
        name: 'RaceAndWork',
        component:  () => import("@/views/RaceAndWorkView"),
      },
      {
        path: 'status',
        name: 'Status',
        component:  () => import("@/views/StatusView"),
      },
      {
        path: 'ranking',
        name: 'Ranking',
        component:  () => import("@/views/RankingView"),
      },
      {
        path: 'news',
        name: 'News',
        component:  () => import("@/views/NewsView"),
      },
      {
        path: 'person',
        name: 'Person',
        component:  () => import("@/views/Person"),
      },
      {
        path: 'problemDetails',
        name: 'ProblemDetails',
        component:  () => import("@/views/ProblemDetailsView"),
      },
      {
        path: 'statusDetails',
        name: 'StatusDetails',
        component:  () => import("@/views/StatusDetailsView"),
      },
      {
        path: 'problemSubRecords',
        name: 'ProblemSubRecords',
        component:  () => import("@/views/ProblemSubRecordsView"),
      },
      {
        path: 'problemAdmin',
        name: 'ProblemAdmin',
        component:  () => import("@/views/ProblemAdminView"),
      },
      {
        path: 'fileManage',
        name: 'FileManage',
        component:  () => import("@/views/FileManageView"),
      },
      {
        path: 'desktop',
        name: 'desktop',
        component: desktop
      },
      {
        path: 'faceList',
        name: 'face',
        component: () => import("@/components/face/index.vue")
      },
      {
        path: 'faceLog',
        name: 'log',
        component: () => import("@/components/faceLog/index.vue")
      }
    ]
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import("@/views/RegisterView")
  },
  {
    path: '/login',
    name: 'login',
    component: () => import("@/views/LoginView")
  },
  {
    path: '/faceRecognition',
    name: 'faceRecognition',
    component: () => import("@/views/FaceRecognitionView")
  },

]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
// 在刷新页面的时候重置当前路由
// activeRouter()
//
// function activeRouter() {
//   const userStr = sessionStorage.getItem("user")
//   if (userStr) {
//     const user = JSON.parse(userStr)
//     let root = {
//       path: '/',
//       name: 'Layout',
//       component: Layout,
//       redirect: "/home",
//       children: []
//     }
//     user.permissions.forEach(p => {
//       let obj = {
//         path: p.path,
//         name: p.name,
//         component: () => import("@/views/" + p.name)
//       };
//       root.children.push(obj)
//     })
//     if (router) {
//       router.addRoute(root)
//     }
//   }
// }
//
// router.beforeEach((to, from, next) => {
//   if (to.path === '/login' || to.path === '/register') {
//     next()
//     return
//   }
//   let user = sessionStorage.getItem("user") ? JSON.parse(sessionStorage.getItem("user")) : {}
//   if (!user.permissions || !user.permissions.length) {
//     next('/login')
//   } else if (!user.permissions.find(p => p.path === to.path)) {
//     next('/login')
//   } else {
//     next()
//   }
// })
export default router
